 <template>
  <div class="index" v-loading.fullscreen.lock="bodyloading">
    <div class="main">
      <div>
        <p class="tit">门店名称：</p>
        <p>{{ materialsApply.custName }}</p>
      </div>
      <div>
        <p class="tit">门店编码：</p>
        <p>{{ materialsApply.custCode }}</p>
      </div>
      <div>
        <p class="tit">小微：</p>
        <p>{{ materialsApply.tradeName }}</p>
      </div>
      <div>
        <p class="tit">渠道：</p>
        <p>{{ materialsApply.channelName }}</p>
      </div>
      <div>
        <p class="tit">产业：</p>
        <p>{{ materialsApply.industryName }}</p>
      </div>
    </div>
    <div class="splx">
      <p class="title">物流信息</p>
      <div class="text">
        <div>
          <p class="tit">收件人:</p>
          <p>{{ materialsApply.receiveUserName }}</p>
        </div>
        <div>
          <p class="tit">收件人电话:</p>
          <p>{{ materialsApply.receiveUserPhone }}</p>
        </div>
        <div>
          <p class="tit">收货地址:</p>
          <p>
            {{
              materialsApply.receiveProvinceName +
              materialsApply.receiveCityName +
              materialsApply.receiveCountyName +
              materialsApply.receiveDetailsAddress
            }}
          </p>
        </div>
      </div>
    </div>
    <div class="splx">
      <p class="title">审批立项</p>
      <van-steps
        direction="vertical"
        :active="0"
        active-color="#7ac0f3"
        :class="{ current: currentstate }"
      >
        <van-step v-for="(item, index) in operationLogVO.list" :key="index">
          <h3>{{ item.operationResult }}</h3>
          <p v-if="item.operationOpinion">
            审批意见 {{ item.operationOpinion }}
          </p>
          <p>操作人 {{ item.operationUserName }}({{ item.operationUserId }})</p>
          <p>{{ item.operationTime }}</p>
        </van-step>
      </van-steps>
      <div class="more" v-show="operationLogVOstate" @click="more">
        {{ currentstate ? "收起↑" : "更多↓" }}
      </div>
    </div>
    <div class="prddetail" @click="toprddetail">
      <p>物料申请详情</p>
      <p>></p>
    </div>
    <div class="splx qssc">
      <p class="title">物料布置上传</p>
      <p class="desc">请分别上传以下物料的布置照片</p>
      <div class="text">
        <div>
          <p style="width: 100%; font-size: 0.12rem">入户服务贴（至少1张）</p>
        </div>
      </div>
      <div class="uppic">
        <div
          v-show="piclist_ruhu.length >= 1"
          v-for="(item, index) in piclist_ruhu"
          :key="item.index"
        >
          <img :src="item.picAddr" @click="scale(1, index)" />
          <van-icon
            name="clear"
            class="del"
            v-show="item.picAddr"
            @click="delItem(1, item, item.index)"
          />
        </div>
        <div>
          <img
            v-show="piclist_ruhu.length <= 16"
            fit="contain"
            src="../../assets/images/add-dashed.png"
            @click="openImgSelect(1)"
          />
        </div>
      </div>

      <div class="text">
        <div>
          <p style="width: 100%; font-size: 0.12rem">外楣吊旗（至少1张）</p>
        </div>
      </div>
      <div class="uppic">
        <div
          v-show="piclist_waimei.length >= 1"
          v-for="(item, index) in piclist_waimei"
          :key="item.index"
        >
          <img :src="item.picAddr" @click="scale(2, index)" />
          <van-icon
            name="clear"
            class="del"
            v-show="item.picAddr"
            @click="delItem(2, item, item.index)"
          />
        </div>
        <div>
          <img
            v-show="piclist_waimei.length <= 16"
            fit="contain"
            src="../../assets/images/add-dashed.png"
            @click="openImgSelect(2)"
          />
        </div>
      </div>

      <div class="text">
        <div>
          <p style="width: 100%; font-size: 0.12rem">权益展架（至少1张）</p>
        </div>
      </div>
      <div class="uppic">
        <div
          v-show="piclist_quanyi.length >= 1"
          v-for="(item, index) in piclist_quanyi"
          :key="item.index"
        >
          <img :src="item.picAddr" @click="scale(3, index)" />
          <van-icon
            name="clear"
            class="del"
            v-show="item.picAddr"
            @click="delItem(3, item, item.index)"
          />
        </div>
        <div>
          <img
            v-show="piclist_quanyi.length <= 16"
            fit="contain"
            src="../../assets/images/add-dashed.png"
            @click="openImgSelect(3)"
          />
        </div>
      </div>

      <div class="text">
        <div>
          <p style="width: 100%; font-size: 0.12rem">权益展架AAAA（至少1张）</p>
        </div>
      </div>
      <div class="uppic">
        <div
          v-show="piclist_AAAA.length >= 1"
          v-for="(item, index) in piclist_AAAA"
          :key="item.index"
        >
          <img :src="item.picAddr" @click="scale(4, index)" />
          <van-icon
            name="clear"
            class="del"
            v-show="item.picAddr"
            @click="delItem(4, item, item.index)"
          />
        </div>
        <div>
          <img
            v-show="piclist_AAAA.length <= 16"
            fit="contain"
            src="../../assets/images/add-dashed.png"
            @click="openImgSelect(4)"
          />
        </div>
      </div>

      <div class="text">
        <div>
          <p style="width: 100%; font-size: 0.12rem">海报（至少1张）</p>
        </div>
      </div>
      <div class="uppic">
        <div
          v-show="piclist_haibao.length >= 1"
          v-for="(item, index) in piclist_haibao"
          :key="item.index"
        >
          <img :src="item.picAddr" @click="scale(5, index)" />
          <van-icon
            name="clear"
            class="del"
            v-show="item.picAddr"
            @click="delItem(5, item, item.index)"
          />
        </div>
        <div>
          <img
            v-show="piclist_haibao.length <= 16"
            fit="contain"
            src="../../assets/images/add-dashed.png"
            @click="openImgSelect(5)"
          />
        </div>
      </div>
    </div>
    <div class="submit">
      <button @click="submit">提交</button>
    </div>
    <van-action-sheet
      v-model="show"
      :actions="actions"
      cancel-text="取消"
      title="选择上传方式"
      :closeable="false"
      close-on-click-action
      @select="imgSelect"
    ></van-action-sheet>
  </div>
</template>

<script>
import { materialsApplyDetails } from "../../api/app";
import { readyApi } from "hwork-widget-report-component/src/utils/index";
import { ImagePreview } from "vant";
import { set } from "js-cookie";
export default {
  name: "Index",
  components: {},

  data() {
    return {
      header: {
        show: true,
        return: true,
        search: false,
        title: "营销物料申请详情",
        home: "/index",
        close: true,
      },
      currentstate: false,
      bodyloading: false,
      logisticsInfo: "", //物流信息
      materials: "", //物料信息
      materialsApply: "", //物料申请主信息
      operationLogVO: "", //审核立项信息
      isHome: false,
      show: false,
      state: this.$route.query.state,
      applyId: this.$route.query.id,
      actions: [
        { name: "从相册选择", number: 0 },
        { name: "拍摄照片", number: 1 },
      ],
      operationLogVOstate: false,
      piclist_ruhu: [],
      piclist_waimei: [],
      piclist_quanyi: [],
      piclist_AAAA: [],
      piclist_haibao: [],
      isEdit: false,
      qsstate: false,
      imgchangcode: 0,
      imglist: [
        { long:1, msg: "请至少上传一张入户服务贴" },
        { long:1, msg: "请至少上传一张外楣吊旗" },
        { long:0, msg: "请至少上传一张权益展架" },
        { long:0, msg: "请至少上传一张权益展架AAAA" },
        { long:0, msg: "请至少上传一张海报" },
      ],
    };
  },
  created() {
    this.getdetail(this.$route.query.id);
    if (this.state == "2099") {
      this.isEdit = true;
    } else if (this.state == "2006") {
      this.qsstate = true;
    }
  },
  mounted() {
    console.log(this.$route.query.id);
  },

  methods: {
    toprddetail() {
      this.$router.push({
        name: "decoratedetail",
        query: {
          applyId: this.$route.query.id,
        },
      });
    },
    more() {
      this.currentstate = !this.currentstate;
    },
    getdetail(applyId) {
      let that = this
      this.bodyloading = true;
      let json = {
        applyId: applyId,
      };
      materialsApplyDetails(json).then((res) => {
        // console.log(res);
        if ((res.code = 200)) {
          if(that.logisticsInfo){
          that.logisticsInfo = res.data.logisticsInfo;
          }
          
          that.materials = res.data.materials;
          that.operationLogVO = res.data.operationLogVO;
          if (that.operationLogVO.list.length > 3) {
            that.operationLogVOstate = true;
          }
          that.materialsApply = res.data.materialsApply;
          that.bodyloading = false;
        }
      });
    },
    // 打开下拉照片方式
    openImgSelect(code) {
      this.show = true;
      this.imgchangcode = code;
    },
    // 选择照片方式
    imgSelect(val) {
      const that = this;
      let number = 8;
      switch (this.imgchangcode) {
        case 1:
          if (this.piclist_ruhu.length > 0) {
            number -= this.piclist_ruhu.length;
          }
          break;
        case 2:
          if (this.piclist_waimei.length > 0) {
            number -= this.piclist_waimei.length;
          }
          break;
        case 3:
          if (this.piclist_quanyi.length > 0) {
            number -= this.piclist_quanyi.length;
          }
          break;
        case 4:
          if (this.piclist_AAAA.length > 0) {
            number -= this.piclist_AAAA.length;
          }
          break;
        case 5:
          if (this.piclist_haibao.length > 0) {
            number -= this.piclist_haibao.length;
          }
          break;
      }
      // 判断
      let path = "hwork_dev/zxgl/";
      if (process.env.NODE_ENV === "production") {
        path = "hsimg/zxgl/";
      }
      if (val.number === 0) {
        // 从相册选择
        that.operationType = "album";
      } else if (val.number === 1) {
        // 拍照上传
        that.operationType = "camera";
      }
      const req = {
        operationType: that.operationType,
        count: number,
        savePath: path,
      };
      readyApi(() => {
        window.AlipayJSBridge.call("openCameraOrAlbum", req, (res) => {
          if (res.code === 200) {
            res.data.forEach((item) => {
              switch (this.imgchangcode) {
                case 1:
                  that.piclist_ruhu.push({
                    picAddr: item,
                    picType: "RH",
                    applyId: this.applyId,
                  });
                  that.imglist[0].long = that.piclist_ruhu.length
                  break;
                case 2:
                  that.piclist_waimei.push({
                    picAddr: item,
                    picType: "WMDQ",
                    applyId: this.applyId,
                  });
                  that.imglist[1].long = that.piclist_ruhu.length
                  break;
                case 3:
                  that.piclist_quanyi.push({
                    picAddr: item,
                    picType: "QYZJ",
                    applyId: this.applyId,
                  });
                  that.imglist[2].long = that.piclist_ruhu.length
                  break;
                case 4:
                  that.piclist_AAAA.push({
                    picAddr: item,
                    picType: "QYZJA",
                    applyId: this.applyId,
                  });
                  that.imglist[3].long = that.piclist_ruhu.length
                  break;
                case 5:
                  that.piclist_haibao.push({
                    picAddr: item,
                    picType: "HB",
                    applyId: this.applyId,
                  });
                  that.imglist[4].long = that.piclist_ruhu.length
                  break;
              }
            });
            this.$forceUpdate();
          }
        });
      });
    },

    delItem(code, item, index) {
      // console.log(item, index);
      switch (code) {
        case 1:
          this.piclist_ruhu.splice(index, 1);
          break;
        case 2:
          this.piclist_waimei.splice(index, 1);
          break;
        case 3:
          this.piclist_quanyi.splice(index, 1);
          break;
        case 4:
          this.piclist_AAAA.splice(index, 1);
          break;
        case 5:
          this.piclist_haibao.splice(index, 1);
          break;
      }

      this.$forceUpdate();
    },
    scale(code, index) {
      let arr = [];
      switch (code) {
        case 1:
          this.piclist_ruhu.forEach((item) => {
            arr.push(item.picAddr);
          });
          break;
        case 2:
          this.piclist_waimei.forEach((item) => {
            arr.push(item.picAddr);
          });
          break;
        case 3:
          this.piclist_quanyi.forEach((item) => {
            arr.push(item.picAddr);
          });
          break;
        case 4:
          this.piclist_AAAA.forEach((item) => {
            arr.push(item.picAddr);
          });
          break;
        case 5:
          this.piclist_haibao.forEach((item) => {
            arr.push(item.picAddr);
          });
          break;
      }
      ImagePreview({
        images: [...arr],
        startPosition: index,
      });
    },
    submit() {
      let message = []
      for (var i = 0; i < this.imglist.length; i++) {
        if(this.imglist[i].long ==  0){
          // console.log(this.imglist[i].long);
          message.push(this.imglist[i].msg)
          this.$toast(message.join(','));
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.index {
  font-size: 0.14rem;
  > div {
    width: 95vw;
    margin: 0 auto;
    border-radius: 0.03rem;
    background-color: #fff;
    margin-bottom: 0.1rem;
    padding-bottom: 0.05rem;
  }

  .main {
    overflow: hidden;
    .title {
      margin: 0;
      font-size: 0.14rem;
      display: block;
      width: 100%;
      margin-top: 0.1rem;
      font-weight: 700;
      padding: 0 0.15rem;
      padding-bottom: 0.1rem;
      box-sizing: border-box;
      border-bottom: 1px solid #eee;
    }
    > div {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      position: relative;
      height: 0.3rem;
      padding: 0 0.15rem;
      box-sizing: border-box;
      .tit {
        width: 5em;
        text-align: left;
      }
      s {
        text-decoration: none;
        color: red;
      }
      .icon {
        position: absolute;
        font-size: 0.14rem;
        position: absolute;
        right: 0.05rem;
      }
    }
  }
  .splx {
    overflow: hidden;
    padding-bottom: 0;
    .more {
      width: 100%;
      height: 0.4rem;
      line-height: 0.4rem;
      text-align: center;
      border-top: 1px solid #eee;
    }
    p {
      margin: 0;
      font-size: 0.14rem;
    }
    .van-steps {
      max-height: 2.2rem;
    }
    .current {
      max-height: none;
    }
    .title {
      margin: 0;
      font-size: 0.14rem;
      display: block;
      width: 100%;
      margin-top: 0.1rem;
      font-weight: 700;
      padding: 0 0.15rem;
      padding-bottom: 0.1rem;
      box-sizing: border-box;
      border-bottom: 1px solid #eee;
    }
    .text {
      padding: 0.05rem 0;
      > div {
        display: flex;
        justify-content: flex-start;
        position: relative;
        padding: 0 0.15rem;
        box-sizing: border-box;
        p {
          width: 2.5rem;
          line-height: 0.3rem;
        }
        .tit {
          width: 1rem;
          text-align: left;
        }
      }
    }
    .textarea {
      width: 100%;
      padding: 0 0.15rem;
      .van-field {
        border: 1px solid #eee;
        box-sizing: border-box;
        padding: 0.05rem;
      }
    }
    .uppic {
      width: 100%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      flex-wrap: wrap;
      padding: 0 0.15rem;
      box-sizing: border-box;
      margin-top: 0.1rem;
      > div {
        position: relative;
        width: 0.5rem;
        margin-right: 0.1rem;
        margin-bottom: 0.1rem;
        .del {
          font-size: 0.14rem;
          position: absolute;
          right: 0;
          top: 0;
        }
        img {
          width: 0.5rem;
          height: 0.5rem;
          display: block;
        }
      }
    }
    h3 {
      font-size: 0.14rem;
    }
    .evaluatelist {
      width: 100%;
      padding-bottom: 0.1rem;
      > div {
        padding: 0 0.15rem;
        box-sizing: border-box;
        margin-top: 0.1rem;
        > p {
          margin-bottom: 0.05rem;
          font-size: 0.12rem;
        }
      }
    }
  }
  .prddetail {
    height: 0.4rem;
    padding: 0 0.15rem;
    box-sizing: border-box;
    margin: 0.1rem auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .qssc {
    .title {
      margin-bottom: 0.1rem;
    }
    .desc {
      display: block;
      padding: 0 0.15rem;
      box-sizing: border-box;
      margin: 0.1rem 0;
    }
    .text {
      padding: 0;
      > div {
        p {
          line-height: normal;
        }
      }
    }
  }
  .prdlist {
    background: none;
    margin-bottom: 0.05rem;
    > div {
      padding: 0.1rem;
      box-sizing: border-box;
      border-radius: 0.03rem;
      background-color: #fff;
      margin-bottom: 0.1rem;
      &:last-child {
        margin-bottom: 0;
      }
      .top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        >>> .van-checkbox {
          width: 0.2rem;
          height: 0.2rem;
        }
        .img {
          width: 0.7rem;
          height: 0.7rem;
          img {
            width: 100%;
            height: 100%;
            display: flex;
          }
        }
        .text {
          width: 2.3rem;
          p {
            margin: 0;
          }
          .tit {
            color: #f40;
          }
          .code {
            color: #666;
            font-size: 0.12rem;
            margin: 0.05rem 0;
          }
          .desc {
            color: #333;
          }
        }
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        p {
          margin: 0;
        }
      }
    }
  }
  .btnbox {
    background: none;
    margin-top: 0.4rem;
    .van-button {
      width: 100%;
      display: block;
      height: 0.4rem;
      border-radius: 0.4rem;
      color: #fff;
      text-align: center;
      line-height: 0.4rem;
      margin-top: 0.05rem;
      background-color: #2698eb;
    }
  }
  .van-popup {
    width: 100vw;
    margin-bottom: 0;
    padding-bottom: 0;
  }
  .submit {
    width: 95vw;
    height: 0.4rem;
    margin: 0.1rem auto;
    display: flex;
    justify-content: center;
    button {
      width: 100%;
      height: 0.4rem;
      color: #fff;
      border: 0;
      border-radius: 0.4rem;
      background-color: #2698eb;
    }
  }
}
</style>
